package com.example.administrator.myapplication;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.myapplication.fragment.NewsListFragment;
import com.example.administrator.myapplication.fragment.NewsListFragment2;
import com.example.administrator.myapplication.fragment.NewsListFragment3;
import com.example.administrator.myapplication.fragment.NewsListFragment4;

public class MainActivity extends AppCompatActivity {

    private TextView selectedCityTv;
    private Button selectCityBtn;
    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
        NewsListFragment3 newsListFragment3 = new NewsListFragment3();//实例化Fragment对象
        getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment3).commit();
    }


    private void initView() {
        textView1 = findViewById(R.id.fragment1);
        textView2 = findViewById(R.id.fragment2);
        textView3 = findViewById(R.id.fragment3);
        textView4 = findViewById(R.id.fragment4);




    }

    private void initData() {

    }

    private void initEvent() {
       textView1.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               NewsListFragment newsListFragment = new NewsListFragment();//实例化Fragment对象
               getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment).commit();
//               FragmentManager fragmentManager = getFragmentManager();//获取fragment实例化
//               FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();//从FragmentManager中获取Fragment事物并开启
//               fragmentTransaction.replace(R.id.fragment_replace_main,newsListFragment).commit();//提交事物

           }
       });
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NewsListFragment2 newsListFragment2 = new NewsListFragment2();//实例化Fragment对象
                getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment2).commit();//提交事物

            }
        });

        textView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NewsListFragment3 newsListFragment3 = new NewsListFragment3();//实例化Fragment对象
                getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment3).commit();
//                FragmentManager fragmentManager = getFragmentManager();//获取fragment实例化
//                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();//从FragmentManager中获取Fragment事物并开启
//                fragmentTransaction.replace(R.id.fragment_replace_main,newsListFragment3).commit();//提交事物

            }
        });

        textView4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NewsListFragment4 newsListFragment4 = new NewsListFragment4();//实例化Fragment对象
                getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment4).commit();
//                FragmentManager fragmentManager = getFragmentManager();//获取fragment实例化
//                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();//从FragmentManager中获取Fragment事物并开启
//                fragmentTransaction.replace(R.id.fragment_replace_main,newsListFragment4).commit();//提交事物

            }
        });


    }

}